<!DOCTYPE html>

<html class="no-js">

<head>
  <meta charset="utf-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  <title></title>
  <meta name="description" content="" />
  <meta name="viewport" content="width=device-width, initial-scale=1" />

  <script src="https://cdn.bootcss.com/axios/0.19.0-beta.1/axios.js"></script>

  <script src="https://cdn.bootcss.com/vue/2.5.17/vue.js"></script>
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/element-ui/2.11.0/theme-chalk/index.css" />
  <script src="https://cdnjs.cloudflare.com/ajax/libs/element-ui/2.11.0/index.js"></script>
  <link rel="stylesheet" href="../../../lib/index.css" />
  <script src="../../../lib/avue.js"></script>
</head>

<body>
  <div id="app">
    <avue-crud ref="crud" :option="option" @size-change="sizeChange" @current-change="currentChange" :data="data"
      :page="page" @on-load="onLoad"></avue-crud>
  </div>
</body>
<script>
  new Vue({
    el: '#app',
    data() {
      return {
        page: {
          pageSize: 20,
          pageSizes: [20, 100, 150, 200],
          total: 0
        },
        data: [],
        option: {
          align: 'center',
          menuAlign: 'center',
          border: true,
          column: [{
            label: '姓名',
            prop: 'name'
          }, {
            label: '年龄',
            prop: 'sex'
          }]
        }
      }
    },
    methods: {

      sizeChange(val) {

        this.$message.success('行数' + val)
      },
      currentChange(val) {

        this.$message.success('页码' + val)
      },
      onLoad(page) {
        this.$message.success('分页信息:' + JSON.stringify(page))
        this.page.total = 40
        //模拟分页
        if (page.currentPage === 1) {
          this.data = [
            {
              name: '张三',
              sex: '男'
            }
          ]
        } else if (page.currentPage == 2) {
          this.data = [
            {
              name: '李四',
              sex: '女'
            }
          ]
        }
      }
    }
  })
</script>

</html>